import { ObjCreate } from "../../common/ObjCreate";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { ItemData } from "../../../resource/info/ItemData";
import { TCopy } from "../../../../../Message/Db/Tables/TCopy";
import { ItemsUtil } from "../../shortcuts/item/ItemsUtil";
import { Alert } from "../../../../../com/mui/controls/Alert";
import { Language } from "../../../../../extend/language/Language";
import { Global } from "../../../../../com/gengine/global/Global";
import { LayerManager } from "../../../manager/LayerManager";
import { TweenLite } from "../../../../../com/greensock/TweenLite";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { GLabel } from "../../../../../com/mui/controls/GLabel";
type int = number;
//class CopyDrawRewardButton
    
    export  class CopyDrawRewardButton /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.createChildren();
            return;
        }

        /* internal  */createChildren(): void
        {
            this._btn = ObjCreate.createGButton("", 0, 0, 32, 32, this, "CopyDrawMiniButton");
            this._btn.addEventListener(flash.events.MouseEvent.CLICK, this.onButtonClick);
            this._nameLabel = ObjCreate.createLabel("", -20, 37, 72, 20, flash.text.TextFormatAlign.CENTER, this, true, 16776960);
            this._nameLabel.mouseChildren = false;
            this._nameLabel.mouseEnabled = false;
            return;
        }

        /* internal  */onButtonClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.CopyCopyDrawRewards, this._drawItem));
            return;
        }

        public updateData(arg1: ItemData, arg2: TCopy): void
        {
            this._copy = arg2;
            this._drawItem = arg1;
            this._nameLabel.htmlText = ItemsUtil.getItemName(this._drawItem);
            return;
        }

        /* internal  */drawCopyBoxAlertHandler(arg1: int): void
        {
            var flag: int;

            var loc1;
            flag = arg1;
            if (flag != Alert.OK) 
            {
                if (flag == Alert.CANCEL) 
                {
                    Alert.buttonWidth = 75;
                    Alert.okLabel = Language.getString(60055);
                    Alert.calcelLabel = Language.getString(60056);
                    Alert.show(Language.getStringByParam(60057, this._drawItem.itemInfo.item.name), Language.getString(69900), Alert.OK | Alert.CANCEL, null, (arg1: int): void
                    {
                        if (arg1 != Alert.OK) 
                        {
                            hide();
                        }
                        else 
                        {
                            Dispatcher.dispatchEvent(new DataEvent(EventName.CopyCopyDrawRewards, _drawItem));
                        }
                        return;
                    })
                }
            }
            else 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.CopyCopyDrawRewards, this._drawItem));
            }
            return;
        }

        public show(): void
        {
            this.x = Global.stage.stageWidth / 2 + 400;
            this.y = 88;
            LayerManager.uiLayer.addChild(this);
            if (!this._lightMask) 
            {
                this._lightMask = new LightMask();
                this._lightMask.width = 38;
                this._lightMask.height = 35;
            }
            this.addChild(this._lightMask);
            TweenLite.to(this, 1, {"x": Global.stage.stageWidth / 2 + 3});
            return;
        }

        public hide(): void
        {
            if (this._lightMask) 
            {
                if (this._lightMask.parent) 
                {
                    this._lightMask.parent.removeChild(this._lightMask);
                }
                this._lightMask.stop();
                this._lightMask = null;
            }
            if (this.parent) 
            {
                this.parent.removeChild(this);
            }
            return;
        }

        /* internal */ /* var */_copy: TCopy;

        /* internal */ /* var */_drawItem: ItemData;

        /* internal */ /* var */_btn: GButton;

        /* internal */ /* var */_nameLabel: GLabel;

        /* internal */ /* var */_lightMask: LightMask;
    }
